package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.domain.TbClue;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMtpper;
    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    @Override
    @Transactional
    public void addSinessTrackRecord(BusinessTrackVo vo) {

        TbBusinessTrackRecord record = new TbBusinessTrackRecord();
        BeanUtils.copyProperties(vo,record);
        //  由于查询需要用到用户名 调用工具类获取用户名
        String username = SecurityUtils.getUsername();
        record.setCreateBy(username);
        record.setCreateTime(new Date());
        tbBusinessTrackRecordMtpper.addSinessTrackRecord(record);

        TbBusiness business = new TbBusiness();
        BeanUtils.copyProperties(vo,business);
        business.setId(vo.getBusinessId());
        business.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbBusinessMapper.updateTbBusiness(business);
    }

    @Override
    public List<TbBusinessTrackRecord> seleteBusiness(Long id) {
       // tbBusinessTrackRecordMtpper.seleteBusiness(id);
        return tbBusinessTrackRecordMtpper.seleteBusiness(id);
    }

}
